//
//  RedPointButton.m
//  B2C
//
//  Created by 李小龙 on 2017/7/26.
//  Copyright © 2017年 lixiaolong. All rights reserved.
//

#import "RedPointView.h"

@implementation RedPointView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self loadView];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self loadView];
}

- (void)loadView {
    self.view = [[[NSBundle mainBundle] loadNibNamed:@"RedPointView" owner:self options:nil] lastObject];
    self.view.frame = self.bounds;
    [self addSubview:self.view];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.view addGestureRecognizer:tap];
}

- (void)tapAction:(UIGestureRecognizer *)tap {
    if (self.block) {
        self.block(self.tag);
    }
}

- (void)setRedPointText:(NSString *)text {
    
    if (TextIsNotNil(text) && ![text isEqualToString:@"0"]) {
        [_redLabel setHidden:NO];
        if (text.integerValue > 99) {
            text = @" 99+ ";
        }
        
        [_redLabel setText:text];
        [_redLabel sizeToFit];
        [_redLabel setHeight:15];
        [_redLabel setHalfCircleWithColor:[UIColor clearColor]];
        
        CGFloat redW = _redLabel.width;
        if (redW <= 15) {
            [_redLabel setWidth:15];
        }
//        else {
//            [_redLabel setWidth:(redW+5)];
//        }
        
        
    } else {
        [_redLabel setHidden:YES];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
